package com.zzld.core.utils;

import java.io.UnsupportedEncodingException;

import org.apache.commons.codec.binary.Base64;
/** 
 * 封装Base64的工具类 
 * 
 */  
public class Base64Coder{  
    public final static String ENCODING="UTF-8";   
    //加密  
    public static String encoded(String data) throws UnsupportedEncodingException{  
        byte[] b=Base64.encodeBase64(data.getBytes(ENCODING),true);  
        return new String(b,ENCODING);  
    }  
    //解密  
    public static String decode(String data) throws UnsupportedEncodingException{  
        byte[] b=Base64.decodeBase64(data.getBytes(ENCODING));  
        return new String(b,ENCODING);  
    }  
    
    public static void main(String[] args) {
    	try {
			System.out.println(Base64Coder.encoded("o2pHNjgEclXh9T5m9HbTerX9Wj20"));
			System.out.println(Base64Coder.decode("bzJwSE5qZ0VjbFhoOVQ1bTlIYlRlclg5V2oyMA"));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}  

